package org.monkey.socket.plugin.service.impl;

import cn.hutool.json.JSONUtil;
import java.util.List;
import org.monkey.common.constant.config.CommonConstant;
import org.monkey.socket.plugin.entity.SocketMsg;
import org.monkey.socket.plugin.service.IMsgDealAction;
import org.monkey.socket.plugin.service.IMsgPushService;

public class DefaultMsgPushService implements IMsgPushService {

  IMsgDealAction msgDealAction;

  public DefaultMsgPushService(IMsgDealAction msgDealAction) {
    this.msgDealAction = msgDealAction;
  }

  @Override
  public boolean push(SocketMsg socketMsg) {
    return  msgDealAction.dealMsg(null, JSONUtil.toJsonStr(socketMsg));
  }

  @Override
  public boolean pushBatch(List<SocketMsg> socketMsgList) {
    for(SocketMsg socketMsg:socketMsgList) {
      CommonConstant.ITEM_POOL.submit(()->push(socketMsg));
    }
    return true;
  }
}
